package day01;

import java.util.*;
import java.util.Stack;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/12 12:22
 * 力扣 225. 用队列实现栈
 */
public class StackPractice04 {

    LinkedList<Integer> list = new LinkedList<>();
    private int size = 0;

    public StackPractice04() {

    }

    public void push(int x) {
        list.offer(x);
        for (int i = 0; i < size; i++) {
            list.offer(list.poll());
        }
        size++;
    }

    public int pop() {
        if (list.isEmpty()) {
            return -1;
        }
        size--;
        return list.poll();
    }

    public int top() {
        if (list.isEmpty()) {
            return -1;
        }
        return list.peek();
    }

    public boolean empty() {
        return list.isEmpty();
    }
}
